﻿using System;
using System.Linq;
using System.Web.Mvc;
using Icms.Core;
using Icms.Core.Model;
using Icms.Core.Service;
using Icms.WebUI.Builder;
using Icms.WebUI.Dto;
using Omu.Awesome.Mvc;

namespace Icms.WebUI.Controllers
{
    public class ParameterController : Cruder<Parameter, ParameterInput>
    {
        public ParameterController(IMapper<Parameter, ParameterInput> v, ICrudService<Parameter> s)
            : base(s, v)
        {
        }

        public virtual ActionResult Search(Guid? classifierId, int page = 1, int ps = 5)
        {
            var src = classifierId.HasValue ? s.Where(o => o.Classifier.Id == classifierId) : s.GetAll();
            var rows = this.RenderView("rows", src.OrderBy(u => u.Id).Pag(page, ps));

            return Json(new { rows, more = src.Count() > page * ps });
        }
    }
}